package com.example.wxai.controller;



import com.example.wxai.pijo.dto.LikesDto;
import com.example.wxai.pijo.entity.Likes;
import com.example.wxai.result.Result;
import com.example.wxai.service.ILikesService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-12-16
 */
@Slf4j
@RestController
@RequestMapping("/likes")
public class LikesController {
    @Resource
    private ILikesService iLikesService;

    //点赞
    @PostMapping("/likes")
    public Result<String> likes(@RequestBody LikesDto likesDto){
        log.info("用户点赞或者取消点赞");
        iLikesService.likes(likesDto);
        return Result.success();
    }

    //查询文章是否点赞
    @GetMapping("/isLikesToEssay")
    public Result<Boolean> isLikes(String essayId, String userId){
        log.info("查询文章是否点赞");
        Likes likes=iLikesService.isLikes(essayId,userId);
        if(likes!=null){
            return Result.success(true);
        }else {
            return Result.success(false);
        }
    }




}
